import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
import {messages} from "share/common";

export default {

  /*CityGroup
    获取城市组列表
   */
  getCityGroupList ( page, size) {
    return httpFetch.get( `${config.baseUrl}/api/levels/my?page=${page}&size=${size}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*CityGroup
    新增城市组
  */
  addCityGroup (param) {
    return httpFetch.post(`${config.baseUrl}/api/levels`, param)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*CityGroup
    编辑城市组
   */
  editCityGroup (param) {
    return httpFetch.put(`${config.baseUrl}/api/levels`, param)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },


  /*CityGroupAllotCompany
    分配公司
    companyOIDs: 选中的公司们
    levelOID: 当前地点组的levelOID
  */
  allotCompany (companyOIDs, levelOIDs) {
    return httpFetch.put(`${config.baseUrl}/api/levels/relevance/company?${companyOIDs}${levelOIDs}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });

  },

  /*CityGroupAllotCompany
   获取所有地点组
   companyOIDs: 选中的公司们
   levelOID: 当前地点组的levelOID
 */

  getAllPlaceList (deleted, page) {
    return httpFetch.get(`${config.baseUrl}/api/levels/my?deleted=${deleted}&page=0&size=1000`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*CityGroupAllotCompany
   获取一个地点组里的公司
   companyOIDs: 选中的公司们
   levelOID: 当前地点组的levelOID
 */
  getPlaceListCompany (levelOID, page, size) {
    return httpFetch.get(`${config.baseUrl}/api/levels/find/distribution?levelOID=${levelOID}&page=${page}&size=${size}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*CityGroupInfo
    CityGroupDetail
    获取城市组下的城市
    levelOID: 该城市组的levelOID
   */
  getCityGroupCityList (levelOID, page) {
    return httpFetch.get(`${config.baseUrl}/api/areas/by/levelOID?roleType=TENANT&levelOID=${levelOID}&page=${page}&size=10`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*CityGroupDetail
    删除城市组下的城市
    levelOID: 该城市组的levelOID
    areaCode: 该城市的areaCode
    selectType: 选择模式，全选传ALL ,其他不传，传areaCodes 集合
   */
  deleteCityGroupCity (selectedRowKeys, levelOID, isAll) {
    let params = {};
    if(isAll){
      params = {
        levelOID: levelOID,
        selectType: 'ALL',
      }
    }else{
      params = {
        levelOID: levelOID,
        areaCodes: selectedRowKeys,
      }
    }
    return httpFetch.post(`${config.baseUrl}/api/areas/delete/code`, params)
  },

  /*CityGroupDetail
  在详细信息那里点击搜索,搜索城市组里的城市
  params = {
    levelOID: " ",
    keyword: " ",
  }
*/
  searchGroupCity (levelOID, keyword, page, size) {
    return httpFetch.get(`${config.baseUrl}/api/areas/level/search/keyword/v2?levelOID=${levelOID}&keyword=${encodeURIComponent(keyword)}&page=${page}&size=${size}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*CityGroupAddCity
    添加城市
  */
  addCity (params) {
    return httpFetch.put(`${config.baseUrl}/api/levels/associate/areaLevel/v2`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*
  获取某一城市组的详细信息
*/
  getCityGroupDetail (levelOID) {
    return httpFetch.get(`${config.baseUrl}/api/levels/v3/${levelOID}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*
  查询洲际信息列表
  */
  getAllStates () {
    return httpFetch.get(`${config.baseUrl}/api/areas/international/list?type=internation`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*
  根据洲际code获取关联的国家
  */
  getStateCountry (code) {
    return httpFetch.get(`${config.baseUrl}/api/areas/international/list?type=country&code=${code}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  /*
 根据系统值列表类型关键词分页查询模板值列表项
 */
  getTemplateList () {
    return httpFetch.get(`${config.baseUrl}/api/custom/enumerations/template/by/type?type=2030`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },


  //最新修改的 搜索城市接口
  newSearchCity (params, page) {
    return httpFetch.post(`${config.baseUrl}/api/areas/search/standard?page=${page}&size=10`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

}
